$(function() {
	
	//加载提现状态
	sys.selectpicker({
		id : 'withdrawStatus',
		url : rootPath + '/dict/listKeyMapEntites',
		param : {
			keyType : "withdrawStatus"
		},
		valueField : 'keyValue',
		textField : 'keyIntro',
		defaultValue: '0',
		defaultAll : true,
//		loadSuccess: function(){
//			initCustomerGrid();
//		}
	})
	
	  //申请开始时间
    sys.datepicker({id: 'beginTime', type:'datetime'});
	$('#beginTime').val('');
	//申请结束时间
	sys.datepicker({id: 'endTime', type:'datetime'});
	$('#endTime').val('');
	$('.datetime .fa-calendar').on('click', function(){
		$(this).prev().click();
	})
	
	// 定义列
	var columns = [
		{
				field : 'no',
				title : '序号',
				align : 'center',
                valign : 'middle',
				formatter : function(value, row, index) {
					return index + 1;
				}
		},
		{
			field : 'customerName',
			title : '申请人',
			valign : 'middle',
			align : 'center',
		},
		{
				field : 'withdrawMoney',
				title : '提现金额',
				valign : 'middle',
				align : 'center'
		},
		{
				field : 'balanceMoney',
				title : '当前余额',
				valign : 'middle',
				align : 'center'
		},
		{
			field : 'accountNum',
			title : '提现账号',
			valign : 'middle',
			align : 'center'
		},
		{
			field : 'accountName',
			title : '账号姓名',
			valign : 'middle',
			align : 'center'
		},
		{
			field : 'accountType',
			title : '账号类型',
			align : 'center',
			valign : 'middle',
			formatter : function(value, row, index) {
				if (row.accountType == "bank") {
					return row.bankName;
				} else {
					return "支付宝";
				}
			}
		},
		{
				field : 'applyTime',
				title : '申请时间',
				valign : 'middle',
				align : 'center',
				formatter : function(value, row, index) {
					return row.applyTimeStr;
				}
		},
		{
			field : 'withdrawStatus',
			title : '状态',
			align : 'center',
			valign : 'middle',
			formatter : function(value, row, index) {
				if (row.withdrawStatus == "1") {
					return "<span class=\"label label-warning\">待处理</span>";
				} else if (row.withdrawStatus == "2") {
					return "<span class=\"label label-success\">已处理</span>";
				} else if (row.withdrawStatus == "3") {
					return "<span class=\"label label-danger\">已驳回</span>";
				}
			}
		},
		{	
			field : '#',
			title : '操作',
			align : 'center',
			valign : 'middle',
			formatter : function(value, row, index) {
				if (row.withdrawStatus == "1") {
					return "<a href='javaScript:void(0);' class='btn btn-danger btn-xs' onclick='toAudit("
								+ row.id + ")'>处理</a>"
								+ "<a href='javaScript:void(0);' class='btn btn-success btn-xs' onclick='toDetail("
								+ row.id + ")'>详情</a>";
				} else {
					return "<a href='javaScript:void(0);' class='btn btn-success btn-xs' onclick='toDetail(" + row.id + ")'>详情</a>";
				}
			}
		}, ];
		
	// 定义查询回调函数（查询参数在此设置）
	var queryParams = function(params) {
		//客户姓名
		var customerName =  $("#customerName").val();
		//申请开始时间
		var beginTime =  $("#beginTime").val();
		//申请结束时间
		var endTime =  $("#endTime").val();
		//处理状态
		var withdrawStatus =  $("#withdrawStatus").selectpicker("val");
		return {
			rows : params.limit, // 页面大小
			page : params.pageNumber, // 页码
			customerName : customerName,
			beginTime : beginTime,
			endTime : endTime,
			withdrawStatus : withdrawStatus,
		};
	};
 	// 请求json数据的服务器地址	
	var url = rootPath + "/walletWithdraw/listWalletWithdrawPage";
	sys.initTable('walletWithdrawTable', {
		url : url,
		columns : columns,
		queryParams : queryParams,
		striped : true,
		clickToSelect : true
	});

	// 查询
	$('#btnQuery').on('click', function() {
		sys.reloadTable('walletWithdrawTable');
	});
	
	// 清空
	$('#btnClear').on('click', function() {
		$("#customerName").val("");
		$("#beginTime").val("");
		$("#endTime").val("");
		$("#withdrawStatus").selectpicker("val", "");
	});
})

//跳转到处理页面
function toAudit(id){
	sys.showRemote(rootPath + '/walletWithdraw/toAuditWalletWithdraw?id='+id, function() {
	    var code = $("#opt_status").val();
		if (code == '1') {
			sys.showSuccess("处理成功！", sys.reloadTable('walletWithdrawTable'));
		} else if (code == '0') {
			sys.showErr("处理失败！");
		}
	}, {
		title : '提现处理',
		width : 800,
		height : 600
	});
}

//跳转到查看详情页面
function toDetail(id){
	sys.showRemote(rootPath + '/walletWithdraw/toDetailWalletWithdraw?id='+id, function() {
	    
	}, {
		title : '提现处理',
		width : 800,
		height : 600
	});
}